package com.manage.service;

import com.manage.mapper.AdminMapper;
import com.manage.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
public class AdminServiceImpl implements AdminService{

    @Autowired
    private AdminMapper adminMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public void saveAdmin(Admin admin) {
        adminMapper.insert(admin);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public void deleteAdmin(String adminId) {
        Example adminExample = new Example(Admin.class);
        Criteria criteria = adminExample.createCriteria();
        criteria.andEqualTo("adminId", adminId);
        adminMapper.deleteByExample(adminExample);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public Admin queryAdminForLogin(String adminId, String adminPassword) {
        Example adminExample = new Example(Admin.class);
        Criteria criteria = adminExample.createCriteria();
        criteria.andEqualTo("adminId", adminId);
        criteria.andEqualTo("adminPassword", adminPassword);
        Admin result = adminMapper.selectOneByExample(adminExample);
        return result;
    }
}
